package com.pro01.apirednote.controller;

import com.pro01.apirednote.pojo.Result;
import com.pro01.apirednote.service.CommentService;
import com.pro01.apirednote.utils.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/comments")
@RequiredArgsConstructor
public class AdminCommentController {

    private final CommentService commentService;

    // 管理员删除评论
    @DeleteMapping("/{commentId}")
    public Result<Void> deleteComment(@PathVariable Long commentId,
                                      HttpServletRequest request) {
        // 校验管理员身份
        String role = TokenUtil.getRole(request);
        if (!"ADMIN".equalsIgnoreCase(role)) {
            return Result.error("无权限，管理员才能执行该操作");
        }

        return commentService.deleteComment(commentId, 0L, "ADMIN");
    }
}